﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Tapt.Web
{
    public partial class contact : TaptPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MasterPage.ActiveTopTab = Common.HeaderActiveLink.Contact;
            this.MasterPage.SetAjaxPro(typeof(contact), "contact");
        }

        [AjaxPro.AjaxMethod]
        public bool SendMessage()
        {
            string email = System.Web.HttpContext.Current.Request["email"];
            string mes = System.Web.HttpContext.Current.Request["message"];
            string name = System.Web.HttpContext.Current.Request["name"];

            string myEmail = ConfigurationManager.AppSettings["SmtpEmail"].ToString();
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential(myEmail, ConfigurationManager.AppSettings["SmtpPW"].ToString()),
                EnableSsl = true
            };
            string messageText = "From: " + name + Environment.NewLine;
            messageText += "Email: " + email + Environment.NewLine;
            messageText += "Message: " + mes + Environment.NewLine;

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(myEmail);
            message.Subject = "Taptworld Message From " + name;
            message.From = new System.Net.Mail.MailAddress(email);
            message.Body = messageText;

            client.Send(message);

            return true;
        }

        [Obsolete]
        protected void SendMessage(object sender, EventArgs e)
        {
            string myEmail = ConfigurationManager.AppSettings["SmtpEmail"].ToString();
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential(myEmail, ConfigurationManager.AppSettings["SmtpPW"].ToString()),
                EnableSsl = true
            };
            string messageText = "From: " + EmailTxt.Text + Environment.NewLine;
            messageText += "Email: " + EmailTxt.Text + Environment.NewLine;
            messageText += "Message: " + MessageText.Text + Environment.NewLine;   

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(myEmail);
            message.Subject = "Taptworld Message from " + EmailTxt.Text;
            message.From = new System.Net.Mail.MailAddress(EmailTxt.Text);
            message.Body = messageText;
            
            client.Send(message);
        }
    }
}